package com.easyfun.healthmagicbox.comm.json;

import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import com.easyfun.healthmagicbox.pojo.PersonQuestion;

public class PersonQuestionsListJsonWrapper <T extends JsonWrapper> 
extends AbstractListJsonWrapper<T, PersonQuestion>{
	public PersonQuestionsListJsonWrapper()
	{
		super();
	}
	public PersonQuestionsListJsonWrapper(List<PersonQuestion> pps) {
		super(pps);
	}

	
	public void deserializeFromObj(JSONObject obj) throws JSONException {
	
		PersonQuestionsJsonWrapper<?,?> leafwrapper;
			try {
				leafwrapper = PersonQuestionsJsonWrapper.getInstance(
						obj.getJSONObject("DoctorQuestion"), 
						PersonQuestionsJsonWrapper.class);

				mpps.add(leafwrapper.getDataPojo());
			} catch (InstantiationException e) {
				e.printStackTrace();
				throw new JSONException(e.toString());
			} catch (IllegalAccessException e) {
				e.printStackTrace();
				throw new JSONException(e.toString());
			}

	}


	public JSONObject serializeToObj() throws JSONException {
		JSONObject serializedObj = new JSONObject();

		int i = 0;
		for (PersonQuestion pp : mpps) {
			PersonQuestionsJsonWrapper<?,?> leafwrapper = new PersonQuestionsJsonWrapper(
					pp);
			serializedObj.put(String.valueOf(i), leafwrapper.serialize());
			i++;
		}

		return serializedObj;
	}

}
